package com.graphqljava.demo.gql.service.impl;

import com.graphqljava.demo.gql.entity.AchieveInfo;
import com.graphqljava.demo.gql.entity.PersonInfo;
import com.graphqljava.demo.gql.service.AchieveInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * com.graphqljava.demo.gql
 *
 * @author Oscar.Chen
 * @date 6/16/2020 12:04 AM
 */
@Service
public class AchieveInfoServiceImpl implements AchieveInfoService {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public Optional<AchieveInfo> findAchieveInfoById(String id) {
        Query query = new Query(Criteria.where("id").is(id));
        return Optional.ofNullable(mongoTemplate.findOne(query, AchieveInfo.class));
    }

    @Override
    public List<AchieveInfo> allAchieveInfos() {
        return mongoTemplate.findAll(AchieveInfo.class);
    }
}
